/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.manager.create;

import br.com.deployment.daoImpl.ExecutorDAOImpl;
import br.com.deployment.daoImpl.NotaryOfficeDAOImpl;
import br.com.deployment.daoImpl.QuestionnaireDAOImpl;
import br.com.deployment.daoImpl.QuestionnaireResponseDAOImpl;
import br.com.deployment.entities.Executor;
import br.com.deployment.entities.NotaryOffice;
import br.com.deployment.entities.Questionnaire;
import br.com.deployment.entities.QuestionnaireResponse;
import br.com.deployment.enums.TypeQuestionnaire;
import br.com.deployment.utils.Msg;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.event.SelectEvent;

/**
 *
 * @author ely
 */
@ManagedBean
@SessionScoped
public class ManagerCreateQuestionnaireResponse {

    @EJB
    QuestionnaireResponseDAOImpl questionnaireResponseService;
    @EJB
    NotaryOfficeDAOImpl notaryOfficeService;
    @EJB
    ExecutorDAOImpl executorService;
    @EJB
    QuestionnaireDAOImpl questionnaireService;
    
    QuestionnaireResponse questionnaireResponse;
    Questionnaire questionnaire;
    NotaryOffice notaryOffice;
    Executor executor;

    TypeQuestionnaire types[] = TypeQuestionnaire.values();
    
    public ManagerCreateQuestionnaireResponse() {
    }

    @PostConstruct
    public void init() {
        questionnaireResponse = new QuestionnaireResponse();
        questionnaire = new Questionnaire();
        notaryOffice = new NotaryOffice();
        executor = new Executor();
    }

    public void save() {

        questionnaireResponse.setStates(false);
        questionnaireResponse.setExecutor(executor);
        questionnaireResponse.setNotaryOffice(notaryOffice);
        questionnaireResponse.setQuestionnaire(questionnaire);
        questionnaireResponse.setDataCad(new Date());
        questionnaireResponseService.save(questionnaireResponse);
        Msg.messagemInfo("Correição Salvo Com Sucesso ");
        questionnaireResponse = new QuestionnaireResponse();

    }

    public void handleSelectNotary(SelectEvent event) {
        NotaryOffice notary = (NotaryOffice) event.getObject();
        notaryOffice = notaryOfficeService.find(notary.getId());
        System.err.println("HANDLESELECT NOTARY " + notaryOffice);

    }

    public void handleSelectExecutor(SelectEvent event) {
        Executor e = (Executor) event.getObject();
        executor = executorService.find(e.getId());
        System.err.println("HANDLESELECT EXECUTOR " + executor);

    }

    public void handleSelectQuestionnaire(SelectEvent event) {
        Questionnaire q = (Questionnaire) event.getObject();
        questionnaire = questionnaireService.find(q.getId());
        System.err.println("HANDLESELECT EXECUTOR " + questionnaire);
    }

     
    public QuestionnaireResponse getQuestionnaireResponse() {
        return questionnaireResponse;
    }

    public void setQuestionnaireResponse(QuestionnaireResponse questionnaireResponse) {
        this.questionnaireResponse = questionnaireResponse;
    }

    public NotaryOffice getNotaryOffice() {
        return notaryOffice;
    }

    public void setNotaryOffice(NotaryOffice notaryOffice) {
        this.notaryOffice = notaryOffice;
    }

    public Executor getExecutor() {
        return executor;
    }

    public void setExecutor(Executor executor) {
        this.executor = executor;
    }

    public Questionnaire getQuestionnaire() {
        return questionnaire;
    }

    public void setQuestionnaire(Questionnaire questionnaire) {
        this.questionnaire = questionnaire;
    }

    public TypeQuestionnaire[] getTypes() {
        return types;
    }

    public void setTypes(TypeQuestionnaire[] types) {
        this.types = types;
    }
    
    
}
